# -*- coding: utf-8 -*-
import json
import re
import requests


# https://oapi.dingtalk.com/robot/send?access_token=a76a48466dccbd85f17fb8812eb9d5dbdafde55d55a7617fe945efe9fcf592b3
if __name__ == '__main__':
    url="https://oapi.dingtalk.com/robot/send?access_token=a76a48466dccbd85f17fb8812eb9d5dbdafde55d55a7617fe945efe9fcf592b3"
    list2 = [
        "[全员开店订单 - 非预期错误], CREATE_ONE_SUPPLIER, TC17122509261503863804-1, A1775575, 2017-12-25 09:26:16, apply_id: None, id: 3249",
        "[全员开店订单 - 非预期错误], CREATE_ONE_SUPPLIER, TC17122509261503863804-1, A1724332, 2017-12-25 09:26:16, apply_id: None, id: 3249",
        "[全员开店订单 - 非预期错误], CREATE_ONE_SUPPLIER, TC17122509261503863804-1, A1757805, 2017-12-25 09:26:16, apply_id: None, id: 3249"];
    print(list2[:3])
    sellers = []

    for li in list2:
        print(li)
        str1 = re.findall(r'A\d+', li)
        sellers.append(str1[0])
    phones=[]
    playload = {
        "msgtype": "text",
        "text": {
            "content":list2
        },
        "at": {
            "atMobiles": phones,
            "isAtAll":False
        }
    }
    for seller_code in sellers:
        bossurl="https://gh.1000.com/bossApi/getAssignedInfo?userId="+seller_code
        phonejson = requests.get(bossurl)
        # mobile
        phone=json.loads(phonejson.text)['data']['data']['mobile']
        phones.append(phone)
    r = requests.post(url, json=playload)
    print(r)



